package com.qaml.mes.device.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qaml.mes.device.dao.CheckUpkeepRecordRecheckDO;
import com.qaml.mes.device.dao.mapper.CheckUpkeepRecordRecheckMapper;
import com.qaml.mes.device.repository.CheckUpkeepRecordRecheckRepository;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 检保记录复核表 服务实现类
 * </p>
 *
 * @author leikai
 * @since 2024-02-28
 */
@Repository
public class CheckUpkeepRecordRecheckRepositoryImpl implements CheckUpkeepRecordRecheckRepository {

    @Resource
    private CheckUpkeepRecordRecheckMapper checkUpkeepRecordRecheckMapper;

    /**
     * 根据检保记录id查询复核信息
     *
     * @param checkUpkeepRecordId
     * @return
     */
    @Override
    public List<CheckUpkeepRecordRecheckDO> getByCheckUpkeepRecordId(String checkUpkeepRecordId) {
        LambdaQueryWrapper<CheckUpkeepRecordRecheckDO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(CheckUpkeepRecordRecheckDO::getCheckUpkeepRecordId, checkUpkeepRecordId);
        lambdaQueryWrapper.eq(CheckUpkeepRecordRecheckDO::getIsDeleted, 0);
        return checkUpkeepRecordRecheckMapper.selectList(lambdaQueryWrapper);
    }

    @Override
    public void insert(CheckUpkeepRecordRecheckDO checkUpkeepRecordRecheckDO) {
        checkUpkeepRecordRecheckMapper.insert(checkUpkeepRecordRecheckDO);
    }

    @Override
    public List<CheckUpkeepRecordRecheckDO> getByCheckUpkeepRecordIdAndHandleType(String checkUpkeepRecordId, Integer handleType) {
        LambdaQueryWrapper<CheckUpkeepRecordRecheckDO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(CheckUpkeepRecordRecheckDO::getCheckUpkeepRecordId, checkUpkeepRecordId);
        lambdaQueryWrapper.eq(Objects.nonNull(handleType), CheckUpkeepRecordRecheckDO::getHandleType, handleType);
        return checkUpkeepRecordRecheckMapper.selectList(lambdaQueryWrapper);
    }
}
